<template>
  <div :class="{item: true, 'msg-left': direction, 'msg-right': !direction}">
    <div v-if="direction" class="img">{{imgTxt}}</div>
    <div class="message">
      <div class="triangle"></div>
      <div v-if="type === 'text'">{{value}}</div>
    </div>
    <div v-if="!direction" class="img">{{imgTxt}}</div>
  </div>
</template>

<script>
    export default {
        name: "message",
        props: {
            type: {
                type: String,
                default: 'text'
            },
            imgTxt: {
                type: String
            },
            direction: {
                type: Boolean,
                default: false // false 代表右边 ，true 代表左边
            },
            value: {
                type: String,
                default: ''
            }
        }
    }
</script>

<style lang="scss" scoped>
  .item {
    display: flex;
    margin-bottom: 10px;

    .img {
      width: 32px;
      height: 32px;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .message {
      padding: 10px;
      background: #fff;
      border-radius: 5px;
      max-width: 320px;
      text-align: left;
      position: relative;

      .triangle {
        border-style: solid;
        position: absolute;
        top: 13px;
      }

    }
  }

  .msg-left {
    .img {
      margin-right: 10px;
    }

    .triangle {
      border-width: 5px 5px 5px 0;
      border-color: transparent #fff transparent transparent;
      left: -5px;
    }
  }

  .msg-right {
    justify-content: flex-end;

    .img {
      margin-left: 10px;
    }

    .message {
      background: #9eea6a;

      .triangle {
        border-width: 5px 0 5px 5px;
        border-color: transparent transparent transparent #9eea6a;
        right: -5px;
      }
    }
  }
</style>
